#ifndef __TEST_GENERAL_H
#define __TEST_GENERAL_H

#include <stdbool.h>
#include <assert.h>
#include "user_threads.h"

extern bool initilize_uthread_in_each_test;
	/* When this is true, each individual test calls: uthread_init(). */

extern bool thread_ok[UTHREAD_MAX_THREADS];
	/* Each thread i sets the value thread_ok[i] to true when it finishes ok.
	   At the end of the test we verify with are_all_threads_ok() that all the
	   relevant threads finished ok. */

extern double last_running_times[UTHREAD_MAX_THREADS];
/* last_running_times[i] - holds the approximate last time (as returned from
	get_precise_time()) that the thread with id 'i' was running, or negative if
	thread 'i' has never run so far.
*/


#define RUN_TEST(test_function, ok_so_far) do { \
	printf(#test_function); \
	printf(": "); \
	int res = (test_function); \
	if (res) { \
		printf("success\n"); \
	} else{ \
		printf("FAILED!\n"); \
		ok_so_far = false; \
	} \
	} while (0)
/* Runs the test statment 'test_function', which should return bool
   value (true on success). This macro prints a relevant message, and if
  test_function failed then 'ok_so_far' is set to false.
	*/


#define TEST_ASSERT(statement) if (!(statement)) {assert(false); return false;}
/* Runs 'statement' and if it returns false, then
	assert(false) and returns false. */


void init_ofer_test_module();
/* Must be called once before doing anything.
  IMPORTANT: must be called after initializing the user_threads module.
*/

void some_long_operation(double seconds);
/* Does some long operation for 'seconds' seconds.
	report_running_of_curr_thread() is called very often the entire duration
	of this function.

	Note: The actual time spent can differ up to 15% of the requestion
		  'seconds'.
*/

double get_precise_time();
/* Returns the precise time since some "Epoch" in seconds.
*/



void init_individual_test();
/*
1) Initilizes thread_ok[UTHREAD_MAX_THREADS] - to be false.
2) Intilizes all elements in last_running_times to be negative.
*/


bool are_all_threads_ok(int threads_num);
/* Returns true iff all the 'threads_num' first threads have:
	thread_ok[i]==true
*/



void report_running_of_curr_thread();
/* Updates 'last_running_times'.
You should call this very often (whenever relevant) in all running threads.
*/




#endif
